package cn.baseyun.demo.controller;

import cn.baseyun.demo.domain.Users;
import cn.baseyun.demo.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/")
public class IndexController {

    @Autowired
    UsersService usersService;

    @GetMapping("/list")
    public List<Users> listUsers() {
        return usersService.list();
    }

    @GetMapping("/update")
    public boolean updateUsers() {
        Users users = new Users();
        users.setId(1);
        users.setAge(22);
        return usersService.updateById(users);
    }

    @PostMapping("/add")
    public boolean addUsers(@RequestBody Users users) {
        return usersService.save(users);
    }

    @DeleteMapping("/delete/{id}")
    public boolean deleteUsers(@PathVariable Integer id) {
        return usersService.removeById(id);
    }
}
